#include "common.h"
#include "prj_config.h"
#include "heart_rate_interface.h"
#include "common.inc"
#include "utf8_to_unicode.h"
#include "arabic_reshaper.h"
#include "display_interface.h"
#include "blecom.h"
#include "display_ctrl.h"
#include "device_type.h"
#include "string.h"
#include "stdio.h"
ancs_display_ctrl_t ancs_disp_ctrl = {0};
const unsigned char IMAGE_USER_FONT_16X16_DOT[] = {
    /* 数组大小：35 颜色数：2 图片：....bmp*/
    0x0f, 0x00, 0x0e, 0x00, 0x02, 0x00, 0x00, 0x00, 0xdf, 0xff, 0x00, 0xad, 0x01, 0x81, 0x00, 0x82, 0x01, 0x81, 0x00,
    0x82, 0x01, 0x81, 0x00, 0x82, 0x01, 0x81, 0x00, 0x82, 0x01, 0x81, 0x00, 0x82, 0x01, 0x81, 0x00, 0xff, 0x89,
};
const unsigned char ICON_FONT_LIB_UNDEFINE[] = {0x00, 0xFE, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0xFE, 0x00,
                                                0x00, 0x7F, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x7F, 0x00};
void draw_device_info(void)
{
    if (disp_ctrl.loop_cnt == 0)
    {
        disp_ctrl.auto_refresh_time = 500;
        memset(&disp_ctrl.com_data.uint8_temp[100], 0, 64);
        get_show_device_name(&disp_ctrl.com_data.uint8_temp[100], 32);
    }
    uint8_t name[32] = {0};
    char mac_buffer[32] = {0};
    uint8_t hardware[32] = {0};
    uint8_t firmware[32] = {0};
    ble_gap_addr_t p_addr = {0};
    sd_ble_gap_address_get(&p_addr);
    {
        uint8_t mac_addr[4] = {0};
        mac_addr[0] = ((p_addr.addr[1] >> 4) & 0x0F);
        mac_addr[1] = (p_addr.addr[1] & 0x0F);
        mac_addr[2] = ((p_addr.addr[0] >> 4) & 0x0F);
        mac_addr[3] = (p_addr.addr[0] & 0x0F);
        sprintf((char *)name, "%s_%01X%01X%01X%01X", (char *)&disp_ctrl.com_data.uint8_temp[100], mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3]);
    }
    sprintf((char *)hardware, "V%s", HARDWARE_VERSION);
#ifdef HARDWARE_SUFFIX
    sprintf((char *)hardware, "%s%s", (char const *)hardware, HARDWARE_SUFFIX);
#endif
    sprintf((char *)firmware, "%s_%s", FIRMWARE_VERSION, FW_STRING_DATE);
    sprintf(mac_buffer, "%1X%1X:%1X%1X:%1X%1X:%1X%1X:%1X%1X:%1X%1X", p_addr.addr[5] >> 4, p_addr.addr[5] & 0xf, p_addr.addr[4] >> 4, p_addr.addr[4] & 0xf, p_addr.addr[3] >> 4, p_addr.addr[3] & 0xf,
            p_addr.addr[2] >> 4, p_addr.addr[2] & 0xf, p_addr.addr[1] >> 4, p_addr.addr[1] & 0xf, p_addr.addr[0] >> 4, p_addr.addr[0] & 0xf);
    int16_t align_type = align_type_right;

    uint8_t buff[120] = {0};
    utf8_string_to_unicode_string((const uint8_t *)name, buff, sizeof(buff));
    draw_off_chip_string(0, 0, 79, 39, (uint16_t const *)buff, 0, &align_type);
    utf8_string_to_unicode_string((const uint8_t *)hardware, buff, sizeof(buff));
    draw_off_chip_string(0, 40, 79, 79, (uint16_t const *)buff, 0, &align_type);
    utf8_string_to_unicode_string((const uint8_t *)firmware, buff, sizeof(buff));
    draw_off_chip_string(0, 80, 79, 119, (uint16_t const *)buff, 0, &align_type);
    utf8_string_to_unicode_string((const uint8_t *)mac_buffer, buff, sizeof(buff));
    draw_off_chip_string(0, 120, 79, 159, (uint16_t const *)buff, 0, &align_type);
}
